﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace YH.Bluetooth
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        [DllImport("filter.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void filter(float[] source, int sourceLen, float[] target, int b);

        // 你可以创建一个静态方法来更方便地使用这个功能
        public static float[] ApplyFilter(float[] input, int b)
        {
            float[] output = new float[input.Length];
            filter(input, input.Length, output, b);
            return output;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                float[] testData = new float[400];
                for (int i = 0; i < testData.Length; i++) 
                {
                    testData[i] = i;
                }
                // 输出结果
                Console.WriteLine("滤波之前的数据:");
                foreach (float f in testData)
                {
                    Console.WriteLine(f);
                }
                float[] filteredData = ApplyFilter(testData, testData.Length);
                // 输出结果
                Console.WriteLine("Filtered Data:");
                foreach (float f in filteredData)
                {
                    Console.WriteLine(f);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
